package com.pengweiwei.androidzygote.video;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;

import androidx.recyclerview.widget.RecyclerView;

import com.android.volley.Request;
import com.pengweiwei.androidzygote.BR;
import com.pengweiwei.androidzygote.R;
import com.pengweiwei.androidzygote.video.data.VideoApi;
import com.pengweiwei.androidzygote.video.data.beans.VideoItemBean;
import com.putong35.common.app.ui.AppGridFragment;
import com.putong35.common.baseactfrag.adapter.DataBindRecyclerViewAdapter;
import com.putong35.common.baseactfrag.adapter.DataBindViewHolder;
import com.putong35.common.baseactfrag.adapter.RecyclerViewBaseAdapter;
import com.putong35.common.httprequest.UrlParams;
import com.putong35.common.httprequest.responsecallbacks.ListBeanResponseListener;
import com.putong35.common.httprequest.responsecallbacks.ListBeanResponseListenerImpl;
import com.putong35.common.utils.EasyToast;


/**
 */
public class VideoGridFragment1 extends AppGridFragment {
    public static final String TAG = VideoGridFragment1.class.getSimpleName();

    private boolean isEditState = false;

    public VideoGridFragment1() {
        super(2);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setLoadWhenCreate(false);
        setRequestInfo(Request.Method.GET, VideoApi.URL_VIDEO_LIST);
    }


    @Override
    public RecyclerViewBaseAdapter createAdapter() {
        return new DataBindRecyclerViewAdapter<VideoItemBean>(getActivity(), R.layout.listitem_sort_video1, BR.videoItemBean) {
            @Override
            public void onBindHolder(RecyclerView.ViewHolder viewHolder, int i) {
                DataBindViewHolder holder = (DataBindViewHolder) viewHolder;
//                holder.getBinding().setVariable(BR.isEditState, isEditState);
               /* CheckBox checkBox = (holder.getBinding().getRoot().findViewById(R.id.rbtnCheck));
                checkBox.setOnCheckedChangeListener((compoundButton, checked) -> {
                    ((VideoItemBean) VideoGridFragment.this.getData().get(i)).setIsChecked(checked);
                });*/
                super.onBindHolder(viewHolder, i);
            }
        };
    }


    @Override
    public ListBeanResponseListener makeResponseListener() {
        return new ListBeanResponseListenerImpl<VideoItemBean>(VideoItemBean.class, this);
    }


    @Override
    public void onListDataUpdateFailed(int code, String msg) {
        super.onListDataUpdateFailed(code, msg);
        EasyToast.showToast(getActivity(), msg);
    }


    @Override
    public UrlParams makeParams() {
        UrlParams urlParams = new UrlParams();
        urlParams.put("channelId", channel);
        urlParams.put("sorts", sortStr);
        return urlParams;
    }

    private String sortStr = "";
    private String channel;
    public void onSelectChanged(String sort, String channel) {
        this.channel = channel;
        this.sortStr = sort;
        reload();
    }

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long itemId) {
        Log.d(TAG, "onItemClick: ");
        VideoItemBean videoItemBean = (VideoItemBean) getData().get(position);
        VideoDetailActivity.start(getContext(), videoItemBean.getId());
    }
}
